<template>
  <div>
    <div class="recommendforyou" v-if="cartRecommend">
      <div class="title">
        <i class="iconfont icon-zhuangshixian_huaban1"></i>
        <span>为你推荐</span>
        <i class="iconfont icon-zhuangshixian2"></i>
      </div>
      <ul class="list">
        <CommodityCard
          v-for="item in cartRecommend"
          :key="item.id"
          :item="item"
        ></CommodityCard>
      </ul>
    </div>
    <div class="loading" v-else>
      <van-loading type="spinner" />
    </div>
  </div>
</template>

<script>
import { mapMutations, mapState,mapActions } from "vuex";
import CommodityCard from "@/components/CommodityCard";
export default {
  components: {
    CommodityCard,
  },
  methods: {
    ...mapMutations([""]),
    ...mapActions(['getList']),
  },
  computed: {
    ...mapState({
      cartRecommend: (state) => state.data.list.cartRecommend,
    }),
  },
  created(){
      this.getList({
      url: "/product/hot",
      name: "cartRecommend",
    });
  }
};
</script>

<style lang="less">
.recommendforyou {
  width: 100%;
  background-color: #fff;
  padding: 0 15px;
  .title {
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    .iconfont {
      font-size: 30px;
      margin-top: 2px;
    }
    span {
      font-size: 14px;
      margin: 0 10px;
    }
  }
  .list {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    li {
      width: calc((100% - 10px) / 2);
      height: 215px;
      &:nth-of-type(2n-1) {
        margin-right: 10px;
      }
      .desc {
        margin-top: 10px;
        .price {
          font-weight: normal;
        }
      }
    }
  }
}
.loading {
  width: 100%;
  text-align: center;
  padding: 30px 0 ;
}
</style>